import { EventEmitter } from "events";
export class TextModel extends EventEmitter {
    private _spacers:string = '';
    constructor() {
        super()
    }
    private _textChangeEmit () {
        /**发布 */
        this.emit('text-change');
    }
    getSpacers () {
        return this._spacers
    }
    insert (spacerIndex:number, spacers:string) {
        const oldSpacers = this._spacers
        this._spacers = oldSpacers.slice(0, spacerIndex) + spacers + oldSpacers.slice(spacerIndex)
        this._textChangeEmit()
    }
    remove (startIndex:number, endIndex:number) {
        const oldSpacers = this._spacers
        if (startIndex > endIndex) {
            [startIndex, endIndex] = [endIndex, startIndex]   
        }
        this._spacers = oldSpacers.slice(0, startIndex) + oldSpacers.slice(endIndex)
        this._textChangeEmit()
    }
}
export default TextModel;